package com.pengtu.entity.detect;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

import com.pengtu.utils.MathsUtils;

/**
 * Materialspot.
 */
@Entity
@Table(name = "S_Q_DETECT_MATERIALSPOT")
public class Materialspot {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;
	private String projectId;
	private Integer countF901;
	private Integer passF901;
	private Integer countF902;
	private Integer passF902;
	private Integer countF903;
	private Integer passF903;
	private Integer countF904;
	private Integer passF904;
	private Integer countF905;
	private Integer passF905;
	private Integer countF906;
	private Integer passF906;
	private Integer countF907;
	private Integer passF907;
	private Integer countF908;
	private Integer passF908;
	private Date reportdate;
	private String remark;
	private SpotReport spotReport;
	private String id;
	private String groupBy;
	private Date createDate; // 创建时间

	public Materialspot( Long countF901,
			 Long passF901,
			 Long countF902,
			 Long passF902,
			 Long countF903,
			 Long passF903,
			 Long countF904,
			 Long passF904,
			 Long countF905,
			 Long passF905,
			 Long countF906,
			 Long passF906,
			 Long countF907,
			 Long passF907,
			 Long countF908,
			 Long passF908,String groupBy){
		this.countF901 = countF901 == null ? null : countF901.intValue();
		this.passF901 = passF901 == null ? null : passF901.intValue();
		this.countF902 = countF902 == null ? null : countF902.intValue();
		this.passF902 = passF902 == null ? null : passF902.intValue();
		this.countF903 = countF903 == null ? null : countF903.intValue();
		this.passF903 = passF903 == null ? null : passF903.intValue();
		this.countF904 = countF904 == null ? null : countF904.intValue();
		this.passF904 = passF904 == null ? null : passF904.intValue();
		this.countF905 = countF905 == null ? null : countF905.intValue();
		this.passF905 = passF905 == null ? null : passF905.intValue();
		this.countF906 = countF906 == null ? null : countF906.intValue();
		this.passF906 = passF906 == null ? null : passF906.intValue();
		this.countF907 = countF907 == null ? null : countF907.intValue();
		this.passF907 = passF907 == null ? null : passF907.intValue();
		this.countF908 = countF908 == null ? null : countF908.intValue();
		this.passF908 = passF908 == null ? null : passF908.intValue();
		this.groupBy = groupBy;
	}
	public Materialspot( Long countF901,
			 Long passF901,
			 Long countF902,
			 Long passF902,
			 Long countF903,
			 Long passF903,
			 Long countF904,
			 Long passF904,
			 Long countF905,
			 Long passF905,
			 Long countF906,
			 Long passF906,
			 Long countF907,
			 Long passF907,
			 Long countF908,
			 Long passF908){
		this.countF901 = countF901 == null ? null : countF901.intValue();
		this.passF901 = passF901 == null ? null : passF901.intValue();
		this.countF902 = countF902 == null ? null : countF902.intValue();
		this.passF902 = passF902 == null ? null : passF902.intValue();
		this.countF903 = countF903 == null ? null : countF903.intValue();
		this.passF903 = passF903 == null ? null : passF903.intValue();
		this.countF904 = countF904 == null ? null : countF904.intValue();
		this.passF904 = passF904 == null ? null : passF904.intValue();
		this.countF905 = countF905 == null ? null : countF905.intValue();
		this.passF905 = passF905 == null ? null : passF905.intValue();
		this.countF906 = countF906 == null ? null : countF906.intValue();
		this.passF906 = passF906 == null ? null : passF906.intValue();
		this.countF907 = countF907 == null ? null : countF907.intValue();
		this.passF907 = passF907 == null ? null : passF907.intValue();
		this.countF908 = countF908 == null ? null : countF908.intValue();
		this.passF908 = passF908 == null ? null : passF908.intValue();
	}
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(length = 48)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(nullable = false, updatable = false, name = "CREATEDATE")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	@JoinColumn(name = "SID")
	public SpotReport getSpotReport() {
		return spotReport;
	}

	public void setSpotReport(SpotReport spotReport) {
		this.spotReport = spotReport;
	}

	public Materialspot() {
	}

	@Column(name = "PID")
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Column(name = "COUNT_F901", precision = 22, scale = 0)
	public Integer getCountF901() {
		return this.countF901;
	}

	public void setCountF901(Integer countF901) {
		this.countF901 = countF901;
	}

	@Column(name = "PASS_F901", precision = 22, scale = 0)
	public Integer getPassF901() {
		return this.passF901;
	}

	public void setPassF901(Integer passF901) {
		this.passF901 = passF901;
	}

	@Transient
	public Double getPassrateF901() {
		Double a = MathsUtils.div("2",getPassF901(), getCountF901(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F902", precision = 22, scale = 0)
	public Integer getCountF902() {
		return this.countF902;
	}

	public void setCountF902(Integer countF902) {
		this.countF902 = countF902;
	}

	@Column(name = "PASS_F902", precision = 22, scale = 0)
	public Integer getPassF902() {
		return this.passF902;
	}

	public void setPassF902(Integer passF902) {
		this.passF902 = passF902;
	}

	@Transient
	public Double getPassrateF902() {
		Double a = MathsUtils.div("2",getPassF902(), getCountF902(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F903", precision = 22, scale = 0)
	public Integer getCountF903() {
		return this.countF903;
	}

	public void setCountF903(Integer countF903) {
		this.countF903 = countF903;
	}

	@Column(name = "PASS_F903", precision = 22, scale = 0)
	public Integer getPassF903() {
		return this.passF903;
	}

	public void setPassF903(Integer passF903) {
		this.passF903 = passF903;
	}

	@Column(name = "COUNT_F904", precision = 22, scale = 0)
	public Integer getCountF904() {
		return countF904;
	}
	public void setCountF904(Integer countF904) {
		this.countF904 = countF904;
	}
	
	@Column(name = "PASS_F904", precision = 22, scale = 0)
	public Integer getPassF904() {
		return passF904;
	}
	public void setPassF904(Integer passF904) {
		this.passF904 = passF904;
	}
	
	@Column(name = "COUNT_F905", precision = 22, scale = 0)
	public Integer getCountF905() {
		return countF905;
	}
	public void setCountF905(Integer countF905) {
		this.countF905 = countF905;
	}
	
	@Column(name = "PASS_F905", precision = 22, scale = 0)
	public Integer getPassF905() {
		return passF905;
	}
	public void setPassF905(Integer passF905) {
		this.passF905 = passF905;
	}
	
	@Column(name = "COUNT_F906", precision = 22, scale = 0)
	public Integer getCountF906() {
		return countF906;
	}
	public void setCountF906(Integer countF906) {
		this.countF906 = countF906;
	}
	
	@Column(name = "PASS_F906", precision = 22, scale = 0)
	public Integer getPassF906() {
		return passF906;
	}
	public void setPassF906(Integer passF906) {
		this.passF906 = passF906;
	}
	
	@Column(name = "COUNT_F907", precision = 22, scale = 0)
	public Integer getCountF907() {
		return countF907;
	}
	public void setCountF907(Integer countF907) {
		this.countF907 = countF907;
	}
	
	@Column(name = "PASS_F907", precision = 22, scale = 0)
	public Integer getPassF907() {
		return passF907;
	}
	public void setPassF907(Integer passF907) {
		this.passF907 = passF907;
	}
	
	@Column(name = "COUNT_F908", precision = 22, scale = 0)
	public Integer getCountF908() {
		return countF908;
	}
	public void setCountF908(Integer countF908) {
		this.countF908 = countF908;
	}
	
	@Column(name = "PASS_F908", precision = 22, scale = 0)
	public Integer getPassF908() {
		return passF908;
	}
	public void setPassF908(Integer passF908) {
		this.passF908 = passF908;
	}
	@Transient
	public Double getPassrateF903() {
		Double a = MathsUtils.div("2",getPassF903(), getCountF903(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF904() {
		Double a = MathsUtils.div("2",getPassF904(), getCountF904(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF905() {
		Double a = MathsUtils.div("2",getPassF905(), getCountF905(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF906() {
		Double a = MathsUtils.div("2",getPassF906(), getCountF906(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF907() {
		Double a = MathsUtils.div("2",getPassF907(), getCountF907(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF908() {
		Double a = MathsUtils.div("2",getPassF908(), getCountF908(),0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	
	@Temporal(TemporalType.DATE)
	@Column(name = "REPORTDATE", length = 7)
	public Date getReportdate() {
		return this.reportdate;
	}

	public void setReportdate(Date reportdate) {
		this.reportdate = reportdate;
	}

	@Column(name = "REMARK", length = 400)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@Transient
	public double getCountF900() {
		return MathsUtils.sum(getCountF901(), getCountF902(), getCountF903(), getCountF904(), getCountF905(), getCountF906(), getCountF907(), getCountF908());
	}

	@Transient
	public double getPassF900() {
		return MathsUtils.sum(getPassF901(), getPassF902(), getPassF903(), getPassF904(), getPassF905(), getPassF906(), getPassF907(), getPassF908());
	}

	@Transient
	public double getPassrateF900() {
		if(getCountF900()==0){
			return 0;}
		else {
		return MathsUtils.div("2",getPassF900(), getCountF900(), 0.01);
	}
	}
	@Transient
	public String getGroupBy() {
		return this.groupBy;
	}
}
